home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Sources / GrfxRun.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  9.7 KB  |  320 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                            GrfxRun.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Author:                        Anthone Burbidge
  7. //    Creation Date:        3/28/94
  8. //
  9. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //========================================================================================
  12.  
  13. #ifndef _GRFXRUN_
  14. #include "GrfxRun.h"
  15. #endif
  16.  
  17. #if !defined(__EXCEPTIONS__) && defined(qUniversalHeaders)
  18. #include <Exceptions.h>
  19. #undef resumeLabel
  20. #define resumeLabel(exception)
  21. #endif
  22.  
  23. #pragma segment TextPart
  24.  
  25. //========================================================================================
  26. // CLASS CBetterGraphicsRun
  27. //========================================================================================
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // CBetterGraphicsRun::CBetterGraphicsRun
  31. //----------------------------------------------------------------------------------------
  32.  
  33. CBetterGraphicsRun::CBetterGraphicsRun() :
  34.     fExtraWidth(0),
  35.     fSelectionWidth(0)
  36. {
  37. }
  38.  
  39. //----------------------------------------------------------------------------------------
  40. // CBetterGraphicsRun::~CBetterGraphicsRun
  41. //----------------------------------------------------------------------------------------
  42.  
  43. CBetterGraphicsRun::~CBetterGraphicsRun()
  44. {
  45. }
  46.  
  47. //----------------------------------------------------------------------------------------
  48. // CBetterGraphicsRun::InitBetterGraphicsRun
  49. //----------------------------------------------------------------------------------------
  50.  
  51. void CBetterGraphicsRun::InitBetterGraphicsRun(short selectionWidth)
  52. {
  53.     this->IRunObject();
  54.     fSelectionWidth = selectionWidth;
  55. }
  56.  
  57. //----------------------------------------------------------------------------------------
  58. // CBetterGraphicsRun::GetObjFlags
  59. //----------------------------------------------------------------------------------------
  60.  
  61. TObjFlags CBetterGraphicsRun::GetObjFlags()
  62. {
  63.     return CRunObject::GetObjFlags() | kIndivisibleRun | kFixedRangeRun | kHasCustomHilite;
  64. }
  65.  
  66. //----------------------------------------------------------------------------------------
  67. // CBetterGraphicsRun::IsTextRun
  68. //----------------------------------------------------------------------------------------
  69.  
  70. Boolean CBetterGraphicsRun::IsTextRun() const
  71. {
  72.     return false;
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. // CBetterGraphicsRun::SetSelectionWidth
  77. //----------------------------------------------------------------------------------------
  78.  
  79. void CBetterGraphicsRun::SetSelectionWidth(short selectionWidth)
  80. {
  81.     fSelectionWidth = selectionWidth;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. // CBetterGraphicsRun::GetScaledDimensions
  86. //----------------------------------------------------------------------------------------
  87.  
  88. #ifdef txtnScal
  89. void CBetterGraphicsRun::GetScaledDimensions(short* hite, short* width,
  90.                                              const Point* numer/*=nil*/,
  91.                                              const Point* denom/*=nil*/)
  92. #else
  93. void CBetterGraphicsRun::GetScaledDimensions(short* hite, short* width)
  94. #endif
  95. {
  96.     if (!this->GetDimensions(hite, width)) {
  97.         *hite = kDefaultHite;
  98.         *width = kDefaultWidth;
  99.     }
  100.     
  101.     check(fExtraWidth <= 0);
  102.     *width += fExtraWidth;
  103.     
  104. #ifdef txtnScal
  105.     Point adjNumer, adjDenom;
  106.     if (numer) {
  107.         adjNumer = *numer;
  108.         adjDenom = *denom;
  109.     }
  110.     else {adjNumer.h = adjNumer.v = adjDenom.h = adjDenom.v = 1;}
  111.     
  112.     this->AdjustScaleVals(&adjNumer, &adjDenom);
  113.     
  114.     *hite = ScaleVal(*hite, adjNumer.v, adjDenom.v) + 2 * GetSelectionWidth();
  115.     *width = ScaleVal(*width, adjNumer.h, adjDenom.h) + 2 * GetSelectionWidth();
  116. #else
  117.     *hite += 2 * GetSelectionWidth();
  118.     *width += 2 * GetSelectionWidth();
  119. #endif
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. // CBetterGraphicsRun::CalcHiteInfo
  124. //----------------------------------------------------------------------------------------
  125.  
  126. void CBetterGraphicsRun::CalcHiteInfo(short* ascent, short* descent, short* leading)
  127. {
  128.     short hite, width;
  129.     if (!this->GetDimensions(&hite, &width)) {hite = kDefaultHite;}
  130.     
  131.     *ascent = hite + 2 * GetSelectionWidth();
  132.     *descent = 0;
  133.     *leading = 0;
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // CBetterGraphicsRun::AdjustObjRect
  138. //----------------------------------------------------------------------------------------
  139.  
  140. #ifdef txtnScal
  141. void CBetterGraphicsRun::AdjustObjRect(Rect* objRect, Point numer, Point denom)
  142. #else
  143. void CBetterGraphicsRun::AdjustObjRect(Rect* objRect)
  144. #endif
  145. {
  146.     short hite, width;
  147.     
  148.     #ifdef txtnScal
  149.     this->GetScaledDimensions(&hite, &width, &numer, &denom);
  150.     #else
  151.     this->GetScaledDimensions(&hite, &width);
  152.     #endif
  153.     
  154.     short vMargin = RectHite(*objRect) - hite;
  155.     
  156.     objRect->top += vMargin;
  157.     objRect->bottom = objRect->top + hite;
  158.     
  159.     InsetRect(objRect, GetSelectionWidth(), GetSelectionWidth());
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. // CBetterGraphicsRun::GetObjectRect
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void CBetterGraphicsRun::GetObjectRect(const RunPositionPB* paramPb, Rect* objRect)
  167. {
  168.     objRect->top = paramPb->runLineTop;
  169.     objRect->bottom = objRect->top+paramPb->runLineHite;
  170.     objRect->left = paramPb->runLeftEdge;
  171.     objRect->right = objRect->left+paramPb->runTotalWidth;
  172.  
  173.     #ifdef txtnScal
  174.     this->AdjustObjRect(objRect, paramPb->numer, paramPb->denom);
  175.     #else
  176.     this->AdjustObjRect(objRect);
  177.     #endif
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. // CBetterGraphicsRun::DoDrawJust
  182. //----------------------------------------------------------------------------------------
  183.  
  184. void CBetterGraphicsRun::DoDrawJust(DrawJustPb* paramPb)
  185. {
  186.     Rect objRect = *(paramPb->lineRectPtr);
  187.     
  188.     objRect.left = FixRound(paramPb->runLeftEdge);
  189.     TLineRunPtr runPtr = paramPb->runInfo;
  190.     objRect.right = objRect.left+FixRound(runPtr->runWidth + runPtr->runExtraWidth);
  191.     
  192.     #ifdef txtnScal
  193.     this->AdjustObjRect(&objRect, paramPb->numer, paramPb->denom);
  194.     #else
  195.     this->AdjustObjRect(&objRect);
  196.     #endif
  197.     
  198.     this->Draw(&objRect);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. // CBetterGraphicsRun::DoPixel2Char
  203. //----------------------------------------------------------------------------------------
  204.  
  205. void CBetterGraphicsRun::DoPixel2Char(Pixel2CharPb* paramPb)
  206. {
  207.     IndivisiblePixel2Char(paramPb);
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. // CBetterGraphicsRun::DoChar2Pixel
  212. //----------------------------------------------------------------------------------------
  213.  
  214. short CBetterGraphicsRun::DoChar2Pixel(Char2PixelPb* paramPb)
  215. {
  216.     return IndivisibleChar2Pixel(paramPb);
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // CBetterGraphicsRun::SetHilite
  221. //----------------------------------------------------------------------------------------
  222.  
  223. void CBetterGraphicsRun::SetHilite(char oldHilite, char newHilite,
  224.                                    const RunPositionPB* paramPb,
  225.                                    Boolean doDraw)
  226. {
  227.     if (doDraw)
  228.     {
  229.         this->DrawSelection(oldHilite, paramPb);
  230.         this->DrawSelection(newHilite, paramPb);
  231.     }
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // CBetterGraphicsRun::DoMeasure
  236. //----------------------------------------------------------------------------------------
  237.  
  238. Fixed CBetterGraphicsRun::DoMeasure(MeasurePb* paramPb)
  239. {
  240.     short hite, width;
  241.     #ifdef txtnScal
  242.     this->GetScaledDimensions(&hite, &width, ¶mPb->numer, ¶mPb->denom);
  243.     #else
  244.     this->GetScaledDimensions(&hite, &width);
  245.     #endif
  246.     
  247.     return width << 16;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. // CBetterGraphicsRun::DoBreak
  252. //----------------------------------------------------------------------------------------
  253.  
  254. StyledLineBreakCode CBetterGraphicsRun::DoBreak(LineBreakPb* paramPb)
  255. {
  256.     fExtraWidth = 0;
  257.     
  258.     short hite, width;
  259.     this->GetScaledDimensions(&hite, &width);
  260.     
  261.     *(paramPb->widthAvail) -= (width << 16);
  262.     
  263.     Boolean lineStart = (paramPb->breakOffset != 0);
  264.     paramPb->breakOffset = paramPb->breakStartOffset;
  265.     
  266.     StyledLineBreakCode result;
  267.     if (*(paramPb->widthAvail) < 0) {
  268.         if (lineStart) {//the line < object width ==> force break
  269.             result = smBreakChar;
  270.             paramPb->breakOffset += paramPb->breakLen;
  271.             
  272.             TX_DebugMessage((ConstStr255Param)"\p obj can no fit, decrease obj width");
  273.             
  274.             fExtraWidth = short(*paramPb->widthAvail >> 16); //-ive
  275.         }
  276.         else {result = smBreakWord;} //break before the object
  277.     }
  278.     else {
  279.         paramPb->breakOffset += paramPb->breakLen;
  280.         result = (*(paramPb->widthAvail)) ? smBreakOverflow : smBreakWord;
  281.     }
  282.     
  283.     return result;
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. // CBetterGraphicsRun::DrawSelection
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void CBetterGraphicsRun::DrawSelection(char hiliteStat, const RunPositionPB* paramPb)
  291. {
  292.     if (hiliteStat == kSelOff) {return;}
  293.     
  294.     Rect objRect;
  295.     this->GetObjectRect(paramPb, &objRect);
  296.     InsetRect(&objRect, -GetSelectionWidth(), -GetSelectionWidth());
  297.     
  298.     PenState savedPen;
  299.     GetPenState(&savedPen);
  300.     
  301.     PenMode(patXor);
  302.     
  303.     ConstPatternParam pat = (hiliteStat == kSelInactiv) ? &ASLMQDGlobals.gray : &ASLMQDGlobals.black;
  304.     PenPat(pat);
  305.     
  306.     FrameRect(&objRect);
  307.     
  308.     SetPenState(&savedPen);
  309. }
  310.  
  311. //----------------------------------------------------------------------------------------
  312. // CBetterGraphicsRun::SetCursor
  313. //----------------------------------------------------------------------------------------
  314.  
  315. void CBetterGraphicsRun::SetCursor(Point, const RunPositionPB*) const
  316. {
  317.     ::SetCursor(&ASLMQDGlobals.arrow);
  318. }
  319.  
  320.